package com.hzhr.iot.device.service;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.CygQuery;
import com.hzhr.iot.core.annotation.CygQuerys;
import com.hzhr.iot.core.annotation.CygService;
import com.hzhr.iot.core.constant.AccessModeEnum;
import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.device.constant.DeviceOptions;
import com.hzhr.iot.device.constant.Device_ErrorsEnum;
import com.hzhr.iot.device.convertor.IotDeviceConvertor;
import com.hzhr.iot.device.convertor.custom.CollectDeviceCustomConvertor;
import com.hzhr.iot.device.convertor.custom.IotDeviceCustomConvertor;
import com.hzhr.iot.device.dao.IotDeviceDao;
import com.hzhr.iot.device.entity.IotDeviceEntity;
import com.hzhr.iot.device.entity.ext.IotDeviceEntityExt;
import com.hzhr.iot.device.model.concentrator.*;
import com.hzhr.iot.device.queryModel.custom.CollectDeviceCustomQueryModel;
import com.hzhr.iot.device.queryModel.custom.IotDeviceCustomQueryModel;
import com.hzhr.iot.device.service.base.BaseService;
import com.hzhr.iot.login.sdk.model.userCard.UserCardModel;
import com.hzhr.iot.user.sdk.model.company_name.Company_NameGetModel;
import com.hzhr.iot.user.sdk.model.company_name.Company_NameModel;
import com.hzhr.iot.user.sdk.model.dept.DeptGetModel;
import com.hzhr.iot.user.sdk.model.dept.DeptModel;
import com.hzhr.iot.user.sdk.model.dept_name.Dept_NameGetModel;
import com.hzhr.iot.user.sdk.model.dept_name.Dept_NameModel;
import com.hzhr.iot.user.sdk.service.User_Company_NameService;
import com.hzhr.iot.user.sdk.service.User_DeptService;
import com.hzhr.iot.user.sdk.service.User_Dept_NameService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.*;

@Service
@CygService(entity = IotDeviceEntity.class, model = ConcentratorModel.class)
@CygQuerys({
        @CygQuery(name = "_equal_id", query = "equal_id", type = Integer.class),
        @CygQuery(name = "_equal_code", query = "equal_code", type = String.class),
        @CygQuery(name = "_like_des", query = "like_des", type = String.class),
        @CygQuery(name = "_greaterthanorequal_createTime", query = "greaterthanorequal_createTime", type = Date.class),
        @CygQuery(name = "_lessthan_createTime", query = "lessthan_createTime", type = Date.class),
})
public class ConcentratorService extends BaseService {
    @Autowired
    DeviceOptions deviceOptions;
    @Autowired
    User_DeptService user_deptService;
    @Autowired
    IotDeviceCustomConvertor iotDeviceCustomConvertor;

    @Autowired
    IotDeviceDao iotDeviceDao;
    @Autowired
    ConcentratorService concentratorService;
    @Autowired
    User_Company_NameService user_company_nameService;

    @Autowired
    User_Dept_NameService user_dept_nameService;

    //region javadoc注释 : post
    /**
     * 新增集中器 <br/><br/>
     * 简介 : 新增集中器 <br/>
     * 步骤 : <br/>
     * 1. 验证集中器代码 : <br/>
     * 如果存在IotDeviceEntityExt对象满足以下条件，则抛出异常201： <br/>
     *           IotDeviceEntityExt.code = body.code； <br/>
     *           IotDeviceEntityExt.categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')； <br/>
     * 2. 创建集中器 : <br/>
     * 根据body创建IotDeviceEntity对象iotDevice_1， <br/>
     * 额外属性设置规则如下： <br/>
     *           IotDeviceEntity.categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')； <br/>
     *           IotDeviceEntity.companyId = 登录用户.companyId； <br/>
     *           IotDeviceEntity.iotPlatformCode = deviceOptions.getCode('IOT_PLATFORM_TYPE','SELF_BUILD')； <br/>
     *           IotDeviceEntity.iotPlatformDeviceId = body.code； <br/>
     *           IotDeviceEntity.resourceCode = body.deptId所关联的user_service.DeptModel对象dept_1的resourceCode属性值(关联关系：ConcentratorPostModel.deptId = user_service.DeptModel.id)； <br/>
     * 3. 返回信息 : <br/>
     * 根据条件参数查询创建的iotDevice_1对象，根据查询结果组装结果对象并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * CONCENTRATORSERVICE_POST_201 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 验证集中器代码<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 集中器代码已存在<br/>
     * @see ConcentratorPostModel body <br/>
     * @see ConcentratorGetModel result <br/>
     */ 
    //endregion
    //region 说明 : post
    //新增集中器
    //简介 : 新增集中器
    //步骤 :
    //1. 验证集中器代码 :
    //如果存在IotDeviceEntityExt对象满足以下条件，则抛出异常201：
    //          IotDeviceEntityExt.code = body.code；
    //          IotDeviceEntityExt.categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')；
    //2. 创建集中器 :
    //根据body创建IotDeviceEntity对象iotDevice_1，
    //额外属性设置规则如下：
    //          IotDeviceEntity.categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')；
    //          IotDeviceEntity.companyId = 登录用户.companyId；
    //          IotDeviceEntity.iotPlatformCode = deviceOptions.getCode('IOT_PLATFORM_TYPE','SELF_BUILD')；
    //          IotDeviceEntity.iotPlatformDeviceId = body.code；
    //          IotDeviceEntity.resourceCode = body.deptId所关联的user_service.DeptModel对象dept_1的resourceCode属性值(关联关系：ConcentratorPostModel.deptId = user_service.DeptModel.id)；
    //3. 返回信息 :
    //根据条件参数查询创建的iotDevice_1对象，根据查询结果组装结果对象并返回；
    //endregion
    //region 参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局", defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/concentrators", method = RequestMethod.POST)
    //endregion
    public ConcentratorGetModel post(Map<String, String> header, Map<String, Object> query,
                                     ConcentratorPostModel body) throws ServiceException {
        UserCardModel userCard = getUserCard(header);
        //1. 验证集中器代码
        IotDeviceCustomQueryModel queryModel = iotDeviceCustomConvertor.concentratorService_query2queryModel(query);
        queryModel.setEqual_code(body.getCode());
        queryModel.setEqual_categoryCode(deviceOptions.getCode("IOT_DEVICE_CATEGORY", "CONCENTRATOR"));
        queryModel.setShow(true);
        IotDeviceEntityExt iotDeviceEntityExt = iotDeviceDao.selectExt(queryModel);
        if (iotDeviceEntityExt != null) {
            throw new ServiceException(Device_ErrorsEnum.CONCENTRATORSERVICE_POST_201);
        }

        //2. 创建集中器
        IotDeviceEntity iotDevice_1 = iotDeviceCustomConvertor.concentratorPostModel2entity(body);
        String categoryCode = deviceOptions.getCode("IOT_DEVICE_CATEGORY", "CONCENTRATOR");
        //额外属性设置
        iotDevice_1.setCategoryCode(categoryCode);
        iotDevice_1.setCompanyId(userCard.getCompanyId());
        iotDevice_1.setIotPlatformCode(deviceOptions.getCode("IOT_PLATFORM_TYPE", "SELF_BUILD"));
        iotDevice_1.setIotPlatformDeviceId(body.getCode());
        //审计属性
        iotDevice_1.setCreateTime(new Date());
        iotDevice_1.setIsValid(CommonOptions.YES_NO.YES);
        iotDevice_1.setState("1");
        iotDevice_1.setCreateUserId(userCard.getUserId());

        Integer deptId = body.getDeptId();
        Map<String, Object> query1 = new HashMap<>();
        query1.put("_equal_id", deptId);
        query1.put("_show", "one");
        query1.put("_show_info", true);
        DeptGetModel deptGetModel = user_deptService.get(initHeader(header, AccessModeEnum.GLOBAL), query1);
        if (deptGetModel != null) {
            DeptModel dept_1 = deptGetModel.getModel();
            if (dept_1 != null) {
                iotDevice_1.setResourceCode(dept_1.getResourceCode());
            }
        }

        int changeCount = iotDeviceDao.insert(iotDevice_1);

        //3. 返回信息
        query.put("_equal_id", iotDevice_1.getId());
        ConcentratorGetModel result = concentratorService.get(initHeader(header, AccessModeEnum.GLOBAL), query);
        result.setChangeCount(changeCount);
        return result;
    }

    //region javadoc注释 : putById
    /**
     * 更新用户所在物联网设备公司下的集中器 <br/><br/>
     * 简介 : 更新用户所在物联网设备公司下的集中器 <br/>
     * 步骤 : <br/>
     * 1. 查询集中器 : <br/>
     * 查询IotDeviceEntity对象iotDevice_1，筛选规则如下： <br/>
     *           IotDeviceEntity.id = 路径参数id； <br/>
     *           IotDeviceEntity.companyId = 登录用户.companyId； <br/>
     *           IotDeviceEntity.categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')； <br/>
     * 如果iotDevice_1不存在，抛出异常201； <br/>
     * 2. 验证修改信息： <br/>
     * (1) 验证集中器代码： <br/>
     *           如果body.code != iotDevice_1.code，并且存在IotDeviceEntity满足以下条件，则抛出异常202： <br/>
     *               IotDeviceEntity.code = body.code； <br/>
     * 3. 修改集中器 : <br/>
     * 根据body更新iotDevice_1， <br/>
     * 额外属性设置规则如下： <br/>
     *           iotDevice_1.resourceCode = body.deptId所关联的user_service.DeptModel对象dept_1的resourceCode属性值(关联关系：user_service.ConcentratorPostModel.deptId = DeptModel.id)； <br/>
     * 3. 返回信息 : <br/>
     * 根据条件参数查询更新后的iotDevice_1对象，根据查询结果组装结果对象并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/><br/>
     * @param id 编号 <br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * CONCENTRATORSERVICE_PUT_BY_ID_201 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 查询集中器<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 集中器不存在<br/>
     * CONCENTRATORSERVICE_PUT_BY_ID_202 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 验证修改信息<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 集中器代码已存在<br/>
     * @see ConcentratorPutModel body <br/>
     * @see ConcentratorGetModel result <br/>
     */ 
    //endregion
    //region 说明 : putById
    //更新用户所在物联网设备公司下的集中器
    //简介 : 更新用户所在物联网设备公司下的集中器
    //步骤 :
    //1. 查询集中器 :
    //查询IotDeviceEntity对象iotDevice_1，筛选规则如下：
    //          IotDeviceEntity.id = 路径参数id；
    //          IotDeviceEntity.companyId = 登录用户.companyId；
    //          IotDeviceEntity.categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')；
    //如果iotDevice_1不存在，抛出异常201；
    //2. 验证修改信息：
    //(1) 验证集中器代码：
    //          如果body.code != iotDevice_1.code，并且存在IotDeviceEntity满足以下条件，则抛出异常202：
    //              IotDeviceEntity.code = body.code；
    //3. 修改集中器 :
    //根据body更新iotDevice_1，
    //额外属性设置规则如下：
    //          iotDevice_1.resourceCode = body.deptId所关联的user_service.DeptModel对象dept_1的resourceCode属性值(关联关系：user_service.ConcentratorPostModel.deptId = DeptModel.id)；
    //3. 返回信息 :
    //根据条件参数查询更新后的iotDevice_1对象，根据查询结果组装结果对象并返回；
    //endregion
    //region 参数 : putById
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "id", value = "编号", required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局", defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : putById
    @RequestMapping(value = "/concentrators/{id}", method = RequestMethod.PUT)
    //endregion
    public ConcentratorGetModel putById(Map<String, String> header, Integer id, Map<String, Object> query,
                                        ConcentratorPutModel body) throws ServiceException {

        //1. 查询集中器
        UserCardModel userCard = getUserCard(header);
        IotDeviceCustomQueryModel queryModel = new IotDeviceCustomQueryModel();
        queryModel.setEqual_id(id);
        queryModel.setEqual_companyId(userCard.getCompanyId());
        queryModel.setEqual_categoryCode(deviceOptions.getCode("IOT_DEVICE_CATEGORY", "CONCENTRATOR"));
        queryModel.setSet_isValid("1");
        queryModel.setShow(true);
        IotDeviceEntityExt iotDevice_1 = iotDeviceDao.selectEntity(queryModel);
        if (iotDevice_1 == null) {
            throw new ServiceException(Device_ErrorsEnum.CONCENTRATORSERVICE_PUT_BY_ID_201);
        }
        //2. 验证修改信息
        //2.1 验证集中器代码
        //2. 验证修改信息：
        //(1) 验证集中器代码：
        //          如果body.code != iotDevice_1.code，并且存在IotDeviceEntity满足以下条件，则抛出异常202：
        //              IotDeviceEntity.code = body.code；
        IotDeviceCustomQueryModel queryModel1 = new IotDeviceCustomQueryModel();
        queryModel1.setEqual_code(body.getCode());
        queryModel1.setSet_isValid("1");
        int Count = iotDeviceDao.selectCount(queryModel1);
        if (!body.getCode().equals(iotDevice_1.getCode()) && Count > 0){
            throw new ServiceException(Device_ErrorsEnum.CONCENTRATORSERVICE_PUT_BY_ID_202);
        }

        //3. 修改集中器
        iotDevice_1.setCode(body.getCode());
        iotDevice_1.setDes(body.getDes());
        iotDevice_1.setGasCompanyId(body.getCompanyId());
        iotDevice_1.setDeptId(body.getDeptId());

        //额外属性设置
        Integer deptId = body.getDeptId();
        Map<String, Object> query1 = new HashMap<>();
        query1.put("_equal_id", deptId);
        query1.put("_show", "one");
        query1.put("_show_info", true);
        DeptGetModel deptGetModel = user_deptService.get(initHeader(header, AccessModeEnum.GLOBAL), query1);
        if (deptGetModel != null) {
            DeptModel dept_1 = deptGetModel.getModel();
            if (dept_1 != null) {
                iotDevice_1.setResourceCode(dept_1.getResourceCode());
            }
        }
        int changeCount = iotDeviceDao.update(iotDevice_1);

        //3. 返回信息
        query.put("_equal_id", iotDevice_1.getId());
        ConcentratorGetModel result = concentratorService.get(initHeader(header, AccessModeEnum.GLOBAL), query);
        result.setChangeCount(changeCount);
        return result;
    }

    //region javadoc注释 : deleteById
    /**
     * 删除用户所在物联网设备公司下的集中器 <br/><br/>
     * 简介 : 删除用户所在物联网设备公司下的集中器 <br/>
     * 步骤 : <br/>
     * 1. 删除集中器 : <br/>
     * 逻辑删除IotDeviceEntity对象，筛选规则如下： <br/>
     *           IotDeviceEntity.id = 路径参数id； <br/>
     *           IotDeviceEntity.companyId = 登录用户.companyId； <br/>
     *           IotDeviceEntity.categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')； <br/>
     * 2. 返回信息 : <br/>
     * 创建结果对象result,属性设置规则如下： <br/>
     * result.changeCount = 删除数量 <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/><br/>
     * @param id 编号 <br/><br/>
     * @throws ServiceException <br/>
     * @see ConcentratorDeleteModel result <br/>
     */ 
    //endregion
    //region 说明 : deleteById
    //删除用户所在物联网设备公司下的集中器
    //简介 : 删除用户所在物联网设备公司下的集中器
    //步骤 :
    //1. 删除集中器 :
    //逻辑删除IotDeviceEntity对象，筛选规则如下：
    //          IotDeviceEntity.id = 路径参数id；
    //          IotDeviceEntity.companyId = 登录用户.companyId；
    //          IotDeviceEntity.categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')；
    //2. 返回信息 :
    //创建结果对象result,属性设置规则如下：
    //result.changeCount = 删除数量
    //endregion
    //region 参数 : deleteById
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "id", value = "编号", required = true, dataType = "int", paramType = "path"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局", defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : deleteById
    @RequestMapping(value = "/concentrators/{id}", method = RequestMethod.DELETE)
    //endregion
    public ConcentratorDeleteModel deleteById(Map<String, String> header, Integer id,
                                              Map<String, Object> query) throws ServiceException {
        UserCardModel userCard = getUserCard(header);
        //1. 删除集中器
        IotDeviceCustomQueryModel queryModel = iotDeviceCustomConvertor.concentratorService_query2queryModel(query);
        queryModel.setEqual_id(id);
        queryModel.setEqual_companyId(userCard.getCompanyId());
        queryModel.setEqual_categoryCode(deviceOptions.getCode("IOT_DEVICE_CATEGORY", "CONCENTRATOR"));
        queryModel.setSet_isValid(CommonOptions.YES_NO.NO);
        queryModel.setSet_updateTime(new Date());
        queryModel.setSet_updateUserId(userCard.getUserId());
        int changeCount = iotDeviceDao.updateProps(queryModel);
        //2. 返回信息
        ConcentratorDeleteModel result = new ConcentratorDeleteModel();
        result.setChangeCount(changeCount);
        return result;
    }

    //region javadoc注释 : get
    /**
     * 查询用户所在物联网设备公司下的集中器 <br/><br/>
     * 简介 : 查询用户所在物联网设备公司下的集中器 <br/>
     * 步骤 : <br/>
     * 1. 查询集中器 : <br/>
     * 根据条件参数查询IotDeviceEntityExt对象列表iotDeviceList_1及总数， <br/>
     * 额外筛选条件如下： <br/>
     *           IotDeviceEntityExt.categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')； <br/>
     *           IotDeviceEntityExt.companyId = 登录用户.companyId； <br/>
     * 2. 返回信息 : <br/>
     * (1) 根据条件参数，将iotDeviceList_1及总数组装成结果对象result <br/>
     * (2) 设置result中ConcentratorModel的部分属性，设置规则如下： <br/>
     *           ConcentratorModel.companyName = ConcentratorModel.companyId所关联的user_service.Company_NameModel的name属性(关联关系：ConcentratorModel.companyId = CompanyNameModel.id) <br/>
     *           ConcentratorModel.deptName = ConcentratorModel.deptId所关联的user_service.Dept_NameModel的name属性(关联关系：ConcentratorModel.deptId = DeptNameModel.id) <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where ConcentratorModel.id = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where ConcentratorModel.code = #{_equal_code};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_des : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where ConcentratorModel.des like '%'#{_like_des} + '%';<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _greaterthanorequal_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where ConcentratorModel.createTime >= #{_greaterthanorequal_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _lessthan_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where ConcentratorModel.createTime < #{_less_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @throws ServiceException <br/>
     * @see ConcentratorGetModel result <br/>
     */ 
    //endregion
    //region 说明 : get
    //查询用户所在物联网设备公司下的集中器
    //简介 : 查询用户所在物联网设备公司下的集中器
    //步骤 :
    //1. 查询集中器 :
    //根据条件参数查询IotDeviceEntityExt对象列表iotDeviceList_1及总数，
    //额外筛选条件如下：
    //          IotDeviceEntityExt.categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')；
    //          IotDeviceEntityExt.companyId = 登录用户.companyId；
    //2. 返回信息 :
    //(1) 根据条件参数，将iotDeviceList_1及总数组装成结果对象result
    //(2) 设置result中ConcentratorModel的部分属性，设置规则如下：
    //          ConcentratorModel.companyName = ConcentratorModel.companyId所关联的user_service.Company_NameModel的name属性(关联关系：ConcentratorModel.companyId = CompanyNameModel.id)
    //          ConcentratorModel.deptName = ConcentratorModel.deptId所关联的user_service.Dept_NameModel的name属性(关联关系：ConcentratorModel.deptId = DeptNameModel.id)
    //endregion
    //region 参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件 : where ConcentratorModel.id = #{equal_id}", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_code", value = "筛选条件 : where ConcentratorModel.code = #{equal_code}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_des", value = "筛选条件 : where ConcentratorModel.des like '%' #{like_des} + '%'", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "greaterthanorequal_createTime", value = "筛选条件 : where ConcentratorModel.createTime >= #{greaterthanorequal_createTime}", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "lessthan_createTime", value = "筛选条件 : where ConcentratorModel.createTime < #{less_createTime}", required = false, dataType = "int", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局", defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where ConcentratorModel.id = #{_equal_id}", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_code", value = "筛选条件 : where ConcentratorModel.code = #{_equal_code}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_des", value = "筛选条件 : where ConcentratorModel.des like '%'#{_like_des} + '%'", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_greaterthanorequal_createTime", value = "筛选条件 : where ConcentratorModel.createTime >= #{_greaterthanorequal_createTime}", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_lessthan_createTime", value = "筛选条件 : where ConcentratorModel.createTime < #{_less_createTime}", required = false, dataType = "int", paramType = "query"),

    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/concentrators", method = RequestMethod.GET)
    //endregion
    public ConcentratorGetModel get(Map<String, String> header, Map<String, Object> query) throws ServiceException {

        //1. 查询集中器
        UserCardModel userCard = getUserCard(header);
        IotDeviceCustomQueryModel queryModel = iotDeviceCustomConvertor.concentratorService_query2queryModel(query);
        queryModel.setEqual_categoryCode(deviceOptions.getCode("IOT_DEVICE_CATEGORY", "CONCENTRATOR"));
        queryModel.setEqual_companyId(userCard.getCompanyId());  //ext_companyExt
        queryModel.setEqual_isValid("1");
        Boolean showInfo = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (showInfo != null && showInfo) {
            queryModel.setShow(true);
        }
        String like_des = HzhrTypeUtil.object2string(query.get("_like_des"));
        String like_des_1 = "%"+like_des+"%";
        if (like_des != null){
            queryModel.setLike_des(like_des_1);
        }
        List<IotDeviceEntityExt> iotDeviceList_1 = null;
        String show = HzhrTypeUtil.object2string(query.get("_show"));
        if (show != null) {
            iotDeviceList_1 = iotDeviceDao.selectExtList(queryModel);
        }
        Boolean showTotal = HzhrTypeUtil.object2boolean(query.get("_show_total"));
        Integer total = null;
        if (showTotal != null && showTotal) {
            total = iotDeviceDao.selectCount(queryModel);
        }
        //2. 返回信息
        ConcentratorGetModel result = iotDeviceCustomConvertor.extList2concentratorGetModel(iotDeviceList_1, total, null, query);
        //one
        ConcentratorModel model = result.getModel();
        if (model != null) {
            Integer companyId = model.getCompanyId();
            Map<String, Object> query1 = new HashMap<>();
            query1.put("_show", "one");
            query1.put("_equal_id", companyId);
            query1.put("_show_info", true);

            Integer deptId = model.getDeptId();
            Map<String, Object> query2 = new HashMap<>();
            query2.put("show", "one");
            query2.put("_equal_id", deptId);
            query2.put("_show_info", true);
            Company_NameGetModel company_nameGetModel = user_company_nameService.get(initHeader(header, AccessModeEnum.GLOBAL), query1);
            Dept_NameGetModel deptNameGetModel = user_dept_nameService.get(initHeader(header, AccessModeEnum.GLOBAL), query2);
            if (company_nameGetModel != null) {
                Company_NameModel companyNameModel = company_nameGetModel.getModel();
                if (companyNameModel != null) {
                    model.setCompanyName(companyNameModel.getName()); //公司名称
                }
                if (deptNameGetModel != null){
                    model.setDeptName(deptNameGetModel.getModel().getName());
                }

            }

            //设置默认的协议编号
            String protocolId = model.getProtocolId();
            if (StringUtils.isEmpty(protocolId)) {//默认设置为重燃协议
                model.setProtocolId("2");
            }
            String protocolDes = deviceOptions.getDesByCode("CCR_PROTOCOL", model.getProtocolId());
            model.setProtocolDes(protocolDes);
        }

        //List
        List<ConcentratorModel> modelList = result.getModelList();
        if (modelList != null) {
            for (ConcentratorModel model2 : modelList) {
                Integer companyId = model2.getCompanyId();
                Map<String, Object> query3 = new HashMap<>();
                query3.put("_show", "list");
                query3.put("_equal_id", companyId);
                query3.put("_show_info", true);
                Company_NameGetModel company_nameGetModel = user_company_nameService.get(initHeader(header, AccessModeEnum.GLOBAL), query3);

                Integer deptId = model2.getDeptId();
                Map<String, Object> query2 = new HashMap<>();
                query2.put("show", "one");
                query2.put("_equal_id", deptId);
                query2.put("_show_info", true);
                Dept_NameGetModel deptNameGetModel = user_dept_nameService.get(initHeader(header, AccessModeEnum.GLOBAL), query2);

                if (company_nameGetModel != null) {
                    List<Company_NameModel> companyNameModel = company_nameGetModel.getModelList();
                    if (companyNameModel != null) {
                        for (Company_NameModel companyNameModel1 : companyNameModel){
                            model2.setCompanyName(companyNameModel1.getName()); //公司名称
                        }

                    }
                }
                if (deptNameGetModel != null){
                    Dept_NameModel deptNameGetModels = deptNameGetModel.getModel();
                        model2.setDeptName(deptNameGetModels.getName());
                }

                //设置默认的协议
                String protocolId = model2.getProtocolId();
                if (StringUtils.isEmpty(protocolId)) {//默认设置为重燃协议
                    model2.setProtocolId("2");
                }
                String protocolDes = deviceOptions.getDesByCode("CCR_PROTOCOL", model2.getProtocolId());
                model2.setProtocolDes(protocolDes);
            }
        }
        return result;
    }




    //region javadoc注释 : get1
    /**
     * 查询集中器 <br/><br/>
     * 简介 : 查询集中器 <br/>
     * 步骤 : <br/>
     * 1. 查询集中器 : <br/>
     * 根据条件参数查询IotDeviceEntityExt对象列表iotDeviceList_1及总数， <br/>
     * 额外筛选条件如下： <br/>
     *           IotDeviceEntityExt[i].categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')； <br/>
     * 2. 返回信息 : <br/>
     * (1) 设置iotDeviceList_1元素额外属性，设置规则如下： <br/>
     *           iotDeviceList_1[i].companyName = iotDeviceList_1[i].companyId所关联的user_service.CompanyNameModel的name属性(关联关系：IotDeviceEntityExt.companyId = CompanyNameModel.id) <br/>
     *           iotDeviceList_1[i].deptName = iotDeviceList_1[i].deptId所关联的user_service.DeptNameModel的name属性(关联关系：IotDeviceEntityExt.deptId = DeptNameModel.id) <br/>
     * (2) 根据条件参数，将iotDeviceList_1及总数组装成结果对象并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where ConcentratorModel.id = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where ConcentratorModel.code = #{_equal_code};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_des : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where ConcentratorModel.des like '%'#{_like_des} + '%';<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _greaterthanorequal_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where ConcentratorModel.createTime >= #{_greaterthanorequal_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _less_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where ConcentratorModel.createTime < #{_less_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @throws ServiceException <br/>
     * @see ConcentratorGetModel result <br/>
     */ 
    //endregion
    //region 说明 : get1
    //查询集中器
    //简介 : 查询集中器
    //步骤 :
    //1. 查询集中器 :
    //根据条件参数查询IotDeviceEntityExt对象列表iotDeviceList_1及总数，
    //额外筛选条件如下：
    //          IotDeviceEntityExt[i].categoryCode = deviceOptions.getCode('IOT_DEVICE_CATEGORY','CONCENTRATOR')；
    //2. 返回信息 :
    //(1) 设置iotDeviceList_1元素额外属性，设置规则如下：
    //          iotDeviceList_1[i].companyName = iotDeviceList_1[i].companyId所关联的user_service.CompanyNameModel的name属性(关联关系：IotDeviceEntityExt.companyId = CompanyNameModel.id)
    //          iotDeviceList_1[i].deptName = iotDeviceList_1[i].deptId所关联的user_service.DeptNameModel的name属性(关联关系：IotDeviceEntityExt.deptId = DeptNameModel.id)
    //(2) 根据条件参数，将iotDeviceList_1及总数组装成结果对象并返回；
    //endregion
    //region 参数 : get1
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件 : where ConcentratorModel.id = #{equal_id}", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_code", value = "筛选条件 : where ConcentratorModel.code = #{equal_code}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_des", value = "筛选条件 : where ConcentratorModel.des like '%'#{like_des} + '%'", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "greaterthanorequal_createTime", value = "筛选条件 : where ConcentratorModel.createTime >= #{greaterthanorequal_createTime}", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "less_createTime", value = "筛选条件 : where ConcentratorModel.createTime < #{less_createTime}", required = false, dataType = "int", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局", defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where ConcentratorModel.id = #{_equal_id}", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_code", value = "筛选条件 : where ConcentratorModel.code = #{_equal_code}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_des", value = "筛选条件 : where ConcentratorModel.des like '%'#{_like_des} + '%'", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_greaterthanorequal_createTime", value = "筛选条件 : where ConcentratorModel.createTime >= #{_greaterthanorequal_createTime}", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_less_createTime", value = "筛选条件 : where ConcentratorModel.createTime < #{_less_createTime}", required = false, dataType = "int", paramType = "query"),

    })
    //endregion
    //region 请求 : get1
    @RequestMapping(value = "/v1/concentrators", method = RequestMethod.GET)
    //endregion
    public ConcentratorGetModel get1(Map<String, String> header, Map<String, Object> query) throws ServiceException {
        //1. 查询集中器
        UserCardModel userCard = getUserCard(header);
        IotDeviceCustomQueryModel queryModel = iotDeviceCustomConvertor.concentratorService_query2queryModel(query);
        queryModel.setEqual_categoryCode(deviceOptions.getCode("IOT_DEVICE_CATEGORY", "CONCENTRATOR"));
        Boolean showInfo = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (showInfo != null && showInfo) {
            queryModel.setShow(true);
        }
        String like_des = HzhrTypeUtil.object2string(query.get("_like_des"));
        String like_des_1 = "%"+like_des+"%";
        if (like_des != null){
            queryModel.setLike_des(like_des_1);
        }
        List<IotDeviceEntityExt> iotDeviceList_1 = null;
        String show = HzhrTypeUtil.object2string(query.get("_show"));
        if (show != null) {
            iotDeviceList_1 = iotDeviceDao.selectExtList(queryModel);
        }
        int total = iotDeviceDao.selectCount(queryModel);
        //2. 返回信息
        ConcentratorGetModel result = iotDeviceCustomConvertor.extList2concentratorGetModel(iotDeviceList_1, total, null, query);
        //one
        ConcentratorModel model = result.getModel();
        if (model != null) {
            Integer companyId = model.getCompanyId();
            Map<String, Object> query1 = new HashMap<>();
            query1.put("_show", "one");
            query1.put("_equal_id", companyId);
            query1.put("_show_info", true);

            Integer deptId = model.getDeptId();
            Map<String, Object> query2 = new HashMap<>();
            query2.put("show", "one");
            query2.put("_equal_id", deptId);
            query2.put("_show_info", true);
            Company_NameGetModel company_nameGetModel = user_company_nameService.get(initHeader(header, AccessModeEnum.GLOBAL), query1);
            Dept_NameGetModel deptNameGetModel = user_dept_nameService.get(initHeader(header, AccessModeEnum.GLOBAL), query2);
            if (company_nameGetModel != null) {
                Company_NameModel companyNameModel = company_nameGetModel.getModel();
                if (companyNameModel != null) {
                    model.setCompanyName(companyNameModel.getName()); //公司名称
                }
                if (deptNameGetModel != null){
                    model.setDeptName(deptNameGetModel.getModel().getName());
                }

            }

            //设置默认的协议编号
            String protocolId = model.getProtocolId();
            if (StringUtils.isEmpty(protocolId)) {//默认设置为重燃协议
                model.setProtocolId("2");
            }
        }

        //List
        List<ConcentratorModel> modelList = result.getModelList();
        if (modelList != null) {
            for (ConcentratorModel model2 : modelList) {
                Integer companyId = model2.getCompanyId();
                Map<String, Object> query3 = new HashMap<>();
                query3.put("_show", "list");
                query3.put("_equal_id", companyId);
                query3.put("_show_info", true);
                Company_NameGetModel company_nameGetModel = user_company_nameService.get(initHeader(header, AccessModeEnum.GLOBAL), query3);

                Integer deptId = model2.getDeptId();
                Map<String, Object> query2 = new HashMap<>();
                query2.put("show", "one");
                query2.put("_equal_id", deptId);
                query2.put("_show_info", true);
                Dept_NameGetModel deptNameGetModel = user_dept_nameService.get(initHeader(header, AccessModeEnum.GLOBAL), query2);

                if (company_nameGetModel != null) {
                    List<Company_NameModel> companyNameModel = company_nameGetModel.getModelList();
                    if (companyNameModel != null) {
                        for (Company_NameModel companyNameModel1 : companyNameModel){
                            model2.setCompanyName(companyNameModel1.getName()); //公司名称
                        }

                    }

                }
                if (deptNameGetModel != null){
                    Dept_NameModel deptNameGetModels = deptNameGetModel.getModel();
                    model2.setDeptName(deptNameGetModels.getName());
                }

                //设置默认的协议编号
                String protocolId = model2.getProtocolId();
                if (StringUtils.isEmpty(protocolId)) {//默认设置为重燃协议
                    model2.setProtocolId("2");
                }

            }


        }
        return result;
    }

}

